package ua.privatbank.test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class EnterToP24Runnable implements Runnable {

    private WebDriver driver;

    public EnterToP24Runnable(WebDriver driver) {
        this.driver = driver;
    }

    @Override
    public void run() {
        try {
            while(!isFieldsDone(2)) {

            }
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }

    private boolean isFieldsDone(int length) throws InterruptedException {
        boolean result = true;
        for(WebElement element: driver.findElements(By.className("otp-item-field"))) {
            result &= (element.getText().length()==length);
            System.out.printf("[%s]: Text:%s Length:%d\n",
                    element.getAttribute("item"), element.getText(), element.getText().length());
        }
        Thread.sleep(2000);
        return result;
    }
}
